package com.yang.prototype.domain.entity;

import com.yang.prototype.domain.dto.UserDto;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author yang
 * @version 0.1
 * @date 2019/4/15
 */
@Data
@Builder
public class UserEntity implements Cloneable {

    private String username;
    private String password;

    private Set<String> roleSet = new HashSet<>();

    @Override
    public Object clone() throws CloneNotSupportedException {

        UserDto userDto = new UserDto();
        userDto.setUsername(this.getUsername());
        userDto.setPassword(this.getPassword());
        Set<String> objectSet = new HashSet<>();
        for (String role : roleSet) {
            objectSet.add(role);
        }
        userDto.setRoleSet(objectSet);

        return userDto;
    }
}
